﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("+");
            comboBox1.Items.Add("-");
            comboBox1.Items.Add("*");
            comboBox1.Items.Add("/");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s1 = textBox1.Text;
            string s2 = textBox2.Text;
            int i1, i2;
            i1 = Convert.ToInt32(s1);
            i2 = Convert.ToInt32(s2);
            int result;
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    result = i1 + i2;
                    break;
                case 1:
                    result = i1 - i2;
                    break;
                case 2:
                    result = i1 * i2;
                    break;
                case 3:
                    if (i2 == 0)
                    {
                        MessageBox.Show("除数不能为零");
                        return;
                    }
                    result = i1 / i2;
                    break;
                default:
                    throw new Exception("未知的运算符");
            }
            textBox3.Text = Convert.ToString(result);
        }

    }
}
